//
//  PayController.swift
//  TrafficViolation
//
//  Created by eaglelive on 2017/5/31.
//  Copyright © 2017年 eaglelive. All rights reserved.
//

import Foundation
import UIKit
class PayController: BaseController {
    var orderID = ""//订单号
    var totalAmount = ""//总费用
    var mianZe = 0//免责声明是否查看，默认没查看
    var modelType = ""//记录是哪个模块支付
    lazy var payView: PayInfoView = {
        let view = PayInfoView(frame: CGRect(x: 0, y: kStatusBarH + kNavigationBarH, width: kScreenW, height: kScreenH - kStatusBarH + kNavigationBarH))
        return view
    }()
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.
        self.view.backgroundColor = tableBgColor
        setupNavBar(title: "支付订单", isback: true, appearWay: 3, isright: false)//自定义导航
        payView.orderID = orderID
        payView.amount = totalAmount
        self.view.addSubview(payView)
    }
}
extension PayController{
    func checkClick(sender:UIButton){
        if sender.isSelected {
            sender.isSelected = false
            mianZe = 0
        }else{
            sender.isSelected = true
            mianZe = 1
        }
    }
    func payClick(sender:UIButton){
        if 0 ==  mianZe{//免责没有选中
            let alertController = UIAlertController(title: alertTitle, message: "请查阅支付协议免责声明", preferredStyle: .alert)
            let cancelAction = UIAlertAction(title: "确定", style: .cancel, handler: nil)
            alertController.addAction(cancelAction)
            self.present(alertController, animated: true, completion: nil)
        }else if 1000 == self.payView.currentTag{
            weiXin(orderNo: orderID, money: totalAmount, orderType: modelType)
        }else if 1001 == self.payView.currentTag{
            print("选择了支付宝支付")
        }else if 1002 == self.payView.currentTag{
            print("选择了银联卡支付")
        }else{
            let alertController = UIAlertController(title: alertTitle, message: "请选择支付方式", preferredStyle: .alert)
            let cancelAction = UIAlertAction(title: "确定", style: .cancel, handler: nil)
            alertController.addAction(cancelAction)
            self.present(alertController, animated: true, completion: nil)
        }
    }
    func openHtml(sender:UIButton){
        let vc = ShowHtmlInfo()
        vc.appTitle = "支付协议"
        vc.type = "sf005"
        vc.appearWay = 3
        self.present(vc, animated: true, completion: nil)
    }
}
